package com.wc.算法基础课.C第三讲搜索与图论.树与图的深度优先遍历.树的重心;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/14 16:42
 * @description https://www.acwing.com/problem/content/848/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, M = N << 1;
    // 邻接表的头
    static int[] h = new int[N];
    // e[i] 表示i这条边 存边连的点
    static int[] e = new int[M];
    // ne[i] 表示i边连下一条边，存边
    static int[] ne = new int[M];
    static int idx = 1;
    static boolean[] st = new boolean[N];
    static int n, a, b;
    static int ans = N;

    public static void main(String[] args) {
        Arrays.fill(h, -1);
        n = sc.nextInt();
        for (int i = 1; i < n; i++) {
            a = sc.nextInt();
            b = sc.nextInt();
            add(a, b);
            add(b, a);
        }
        dfs(1);
        out.println(ans);
        out.flush();
    }

    static int dfs(int u) {
        st[u] = true;

        int sum = 1, res = 0;
        // 拿到边
        for (int i = h[u]; i != -1; i = ne[i]) {
            // 获得这条表连的点
            int j = e[i];
            if (!st[j]) {
                // 子树最大值
                int s = dfs(j);
                // 保存子树的最大快
                res = Math.max(res, s);
                // 保存包括自己的子树节点个数
                sum += s;
            }
        }
        // 删除u表示的最大值，我们只要将取最大的当中的最小的快就是答案， n - sum 表示的是父节点所联通的块的大小
        res = Math.max(res, n - sum);
        ans = Math.min(res, ans);
        return sum;
    }


    static void add(int a, int b) {
        // 边连b
        e[idx] = b;
        // 头连边
        ne[idx] = h[a];
        h[a] = idx++;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
